package com.work.work.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.work.work.dto.ProjectDTO;
import com.work.work.entity.Project;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;

@Mapper
public interface ProjectMapper extends BaseMapper<Project> {
    @Insert("INSERT INTO t_project_resource (project_id, resource_id, allocated_quantity) VALUES (#{projectId}, #{resourceId}, #{allocatedQuantity})")
    int insertProjectResourceAllocation(@Param("projectId") Integer projectId,
                                        @Param("resourceId") Integer resourceId,
                                        @Param("allocatedQuantity") BigDecimal allocatedQuantity);
    @Insert("INSERT INTO t_project_resource (project_id, resource_id, allocated_quantity) VALUES (#{projectId}, #{resourceId}, #{allocatedQuantity})")
    int insertProjectResource(@Param("projectId") Integer projectId,
                              @Param("resourceId") Integer resourceId,
                              @Param("allocatedQuantity") BigDecimal allocatedQuantity);

    @Select("SELECT p.*, t.teamname as team_name " +
            "FROM t_project p " +
            "LEFT JOIN t_team t ON p.team_id = t.id")
    Page<ProjectDTO> selectProjectPageWithTeamName(Page<ProjectDTO> page);
    @Select("SELECT p.*, t.teamname as team_name " +
            "FROM t_project p " +
            "LEFT JOIN t_team t ON p.team_id = t.id " +
            "WHERE p.project_name LIKE CONCAT('%', #{projectName}, '%')")
    Page<ProjectDTO> selectByProjectName(Page<ProjectDTO> page, @Param("projectName") String projectName);
    @Select("SELECT COUNT(*) FROM t_project ")
    long selectCount(@Param("ew") QueryWrapper<Project> wrapper);

}